package cn.mogugo.joke.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.mogugo.comm.BaseDao;
import cn.mogugo.joke.model.JokeCategory;

public class JokeCategoryDao extends BaseDao{
	public Class getEntityClass(){
		return JokeCategory.class;
	}

	
	public JokeCategory getByCategoryName(String category_name){
		String hql = "from JokeCategory jc where jc.category_name =:category_name ";
		Map map = new HashMap();
		map.put("category_name", category_name);
		List listJc = this.getByHQL(hql, map);
		if(!listJc.isEmpty() && listJc.size() > 0){
			return (JokeCategory)listJc.get(0);
		}else{
			return null;
		}
	}
	
	
	public JokeCategory saveNewCategory(String category_name){
		JokeCategory jc = new JokeCategory();
		jc.setCategory_name(category_name);
		jc.setId(null);
		jc.setJoke_number(null);
		this.saveOrUpdate(jc);
		return jc;
	}
}
